/*********************************************************************
	Rhapsody	: 7.5.2
	Login		: dan
	Component	: TPkg_RobotController_Comp
	Configuration 	: DefaultConfig
	Model Element	: TCSC_tc_0
//!	Generated Date	: Sat, 18, Dec 2010 
	File Path	: TPkg_RobotController_Comp/DefaultConfig/TPkg_RobotController/TCSC_tc_0.java
*********************************************************************/

package TPkg_RobotController;

//## dependency RobotPkg 
import RobotPkg.*;
//## operation TCSC_tc_0( TCon_RobotController, RobotController) 
import RobotPkg.RobotController;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.*;
//## auto_generated
import org.btc.TestConductor.TestConductor;
//## auto_generated
import com.ibm.rational.rhapsody.animation.*;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.states.*;
//## auto_generated
import com.ibm.rational.rhapsody.animcom.animMessages.*;

//----------------------------------------------------------------------------
// TPkg_RobotController/TCSC_tc_0.java                                                                  
//----------------------------------------------------------------------------

//## package TPkg_RobotController 


//## class TCSC_tc_0 
public class TCSC_tc_0 implements RiJStateConcept, Animated {
    
    public Reactive reactive;		//## ignore 
    
    protected RobotController itsRobotController;		//## link itsRobotController 
    
    protected TCon_RobotController itsTCon;		//## link itsTCon 
    
    //#[ ignore 
    public static final int RiJNonState=0;
    public static final int terminationstate_0=1;
    public static final int state_4=2;
    public static final int state_3=3;
    public static final int state_1=4;
    public static final int initial=5;
    public static final int final_state=6;
    //#]
    protected int rootState_subState;		//## ignore 
    
    protected int rootState_active;		//## ignore 
    
    public static final int TCSC_tc_0_Timeout_state_4_id = 1;		//## ignore 
    
    public static final int TCSC_tc_0_Timeout_state_3_id = 2;		//## ignore 
    
    //#[ ignore
    // Instrumentation attributes (Animation)
    private Animate animate;
    
    public static AnimClass animClassTCSC_tc_0 = new AnimClass("TPkg_RobotController.TCSC_tc_0",false);
    //#]
    
    
    //## statechart_method 
    public RiJThread getThread() {
        return reactive.getThread();
    }
    
    //## statechart_method 
    public void schedTimeout(long delay, long tmID, RiJStateReactive reactive) {
        getThread().schedTimeout(delay, tmID, reactive);
    }
    
    //## statechart_method 
    public void unschedTimeout(long tmID, RiJStateReactive reactive) {
        getThread().unschedTimeout(tmID, reactive);
    }
    
    //## statechart_method 
    public boolean isIn(int state) {
        return reactive.isIn(state);
    }
    
    //## statechart_method 
    public boolean isCompleted(int state) {
        return reactive.isCompleted(state);
    }
    
    //## statechart_method 
    public RiJEventConsumer getEventConsumer() {
        return (RiJEventConsumer)reactive;
    }
    
    //## statechart_method 
    public void gen(RiJEvent event) {
        reactive._gen(event);
    }
    
    //## statechart_method 
    public void queueEvent(RiJEvent event) {
        reactive.queueEvent(event);
    }
    
    //## statechart_method 
    public int takeEvent(RiJEvent event) {
        return reactive.takeEvent(event);
    }
    
    // Constructors
    
    //## operation TCSC_tc_0( TCon_RobotController, RobotController) 
    public  TCSC_tc_0( TCon_RobotController tcon,  RobotController arg_RobotController, RiJThread p_thread) {
        try {
            animInstance().notifyConstructorEntered(animClassTCSC_tc_0.getUserClass(),
               new ArgData[] {
                   new ArgData(TCon_RobotController.class, "tcon", AnimInstance.animToString(tcon)),
                   new ArgData(RobotController.class, "arg_RobotController", AnimInstance.animToString(arg_RobotController))
               });
        
        reactive = new Reactive(p_thread);
        //#[ operation TCSC_tc_0( TCon_RobotController, RobotController) 
        itsTCon = tcon;
        itsRobotController = arg_RobotController;
        
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    //## auto_generated 
    public  TCSC_tc_0(RiJThread p_thread) {
        try {
            animInstance().notifyConstructorEntered(animClassTCSC_tc_0.getUserClass(),
               new ArgData[] {
               });
        
        reactive = new Reactive(p_thread);
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## auto_generated 
    public RobotController getItsRobotController() {
        return itsRobotController;
    }
    
    //## auto_generated 
    public void setItsRobotController(RobotController p_RobotController) {
        itsRobotController = p_RobotController;
        if(p_RobotController != null)
            {
                animInstance().notifyRelationAdded("itsRobotController", p_RobotController);
            }
        else
            {
                animInstance().notifyRelationCleared("itsRobotController");
            }
    }
    
    //## auto_generated 
    public TCon_RobotController getItsTCon() {
        return itsTCon;
    }
    
    //## auto_generated 
    public void setItsTCon(TCon_RobotController p_TCon_RobotController) {
        itsTCon = p_TCon_RobotController;
        if(p_TCon_RobotController != null)
            {
                animInstance().notifyRelationAdded("itsTCon", p_TCon_RobotController);
            }
        else
            {
                animInstance().notifyRelationCleared("itsTCon");
            }
    }
    
    //## auto_generated 
    public boolean startBehavior() {
        boolean done = false;
        done = reactive.startBehavior();
        return done;
    }
    
    //## ignore 
    public class Reactive extends RiJStateReactive implements AnimatedReactive {
        
        // Default constructor 
        public Reactive() {
            this(RiJMainThread.instance());
        }
        
        
        // Constructors
        
        public  Reactive(RiJThread p_thread) {
            super(p_thread);
            initStatechart();
        }
        
        //## statechart_method 
        public boolean isIn(int state) {
            if(rootState_subState == state)
                {
                    return true;
                }
            return false;
        }
        
        //## statechart_method 
        public boolean isCompleted(int state) {
            return true;
        }
        
        //## statechart_method 
        public void rootState_add(AnimStates animStates) {
            animStates.add("ROOT");
            switch (rootState_subState) {
                case initial:
                {
                    initial_add(animStates);
                }
                break;
                case state_1:
                {
                    state_1_add(animStates);
                }
                break;
                case final_state:
                {
                    final_state_add(animStates);
                }
                break;
                case terminationstate_0:
                {
                    terminationstate_0_add(animStates);
                }
                break;
                case state_3:
                {
                    state_3_add(animStates);
                }
                break;
                case state_4:
                {
                    state_4_add(animStates);
                }
                break;
                default:
                    break;
            }
        }
        
        //## statechart_method 
        public void rootState_entDef() {
            {
                rootState_enter();
                rootStateEntDef();
            }
        }
        
        //## statechart_method 
        public int rootState_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            switch (rootState_active) {
                case initial:
                {
                    res = initial_takeEvent(id);
                }
                break;
                case state_1:
                {
                    res = state_1_takeEvent(id);
                }
                break;
                case final_state:
                {
                    res = final_state_takeEvent(id);
                }
                break;
                case terminationstate_0:
                {
                    res = terminationstate_0_takeEvent(id);
                }
                break;
                case state_3:
                {
                    res = state_3_takeEvent(id);
                }
                break;
                case state_4:
                {
                    res = state_4_takeEvent(id);
                }
                break;
                default:
                    break;
            }
            return res;
        }
        
        //## statechart_method 
        public void terminationstate_0_add(AnimStates animStates) {
            animStates.add("ROOT.terminationstate_0");
        }
        
        //## statechart_method 
        public void state_4_add(AnimStates animStates) {
            animStates.add("ROOT.state_4");
        }
        
        //## statechart_method 
        public void state_3_add(AnimStates animStates) {
            animStates.add("ROOT.state_3");
        }
        
        //## statechart_method 
        public void state_1_add(AnimStates animStates) {
            animStates.add("ROOT.state_1");
        }
        
        //## statechart_method 
        public void initial_add(AnimStates animStates) {
            animStates.add("ROOT.initial");
        }
        
        //## statechart_method 
        public void final_state_add(AnimStates animStates) {
            animStates.add("ROOT.final_state");
        }
        
        //## auto_generated 
        protected void initStatechart() {
            rootState_subState = RiJNonState;
            rootState_active = RiJNonState;
        }
        
        //## statechart_method 
        public void state_3_entDef() {
            state_3_enter();
        }
        
        //## statechart_method 
        public void state_4_exit() {
            state_4Exit();
            animInstance().notifyStateExited("ROOT.state_4");
        }
        
        //## statechart_method 
        public void terminationstate_0Exit() {
        }
        
        //## statechart_method 
        public void terminationstate_0Enter() {
        }
        
        //## statechart_method 
        public void state_1Enter() {
        }
        
        //## statechart_method 
        public void state_3_exit() {
            state_3Exit();
            animInstance().notifyStateExited("ROOT.state_3");
        }
        
        //## statechart_method 
        public int final_state_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.NULL_EVENT_ID))
                {
                    res = final_stateTakeNull();
                }
            
            return res;
        }
        
        //## statechart_method 
        public int state_1TakeNull() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("2");
            state_1_exit();
            //#[ transition 2 
            TestConductor.ASSERT_NAME("Sensor initial value", itsRobotController.getSensor(0).getLine() == false);
            
            itsRobotController.getSensor(0).gen(new lineSeen());
            //#]
            state_3_entDef();
            animInstance().notifyTransitionEnded("2");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public int state_3_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.TIMEOUT_EVENT_ID))
                {
                    res = state_3TakeRiJTimeout();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void terminationstate_0_exit() {
            terminationstate_0Exit();
            animInstance().notifyStateExited("ROOT.terminationstate_0");
        }
        
        //## statechart_method 
        public void terminationstate_0_entDef() {
            terminationstate_0_enter();
        }
        
        //## statechart_method 
        public void state_1_exit() {
            popNullConfig();
            state_1Exit();
            animInstance().notifyStateExited("ROOT.state_1");
        }
        
        //## statechart_method 
        public void state_1_entDef() {
            state_1_enter();
        }
        
        //## statechart_method 
        public void terminationstate_0_enter() {
            animInstance().notifyStateEntered("ROOT.terminationstate_0");
            rootState_subState = terminationstate_0;
            rootState_active = terminationstate_0;
            terminationstate_0Enter();
        }
        
        //## statechart_method 
        public void final_stateEnter() {
        }
        
        //## statechart_method 
        public int initial_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.NULL_EVENT_ID))
                {
                    res = initialTakeNull();
                }
            
            return res;
        }
        
        //## statechart_method 
        public int state_3TakeRiJTimeout() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.getTimeoutId() == TCSC_tc_0_Timeout_state_3_id)
                {
                    animInstance().notifyTransitionStarted("4");
                    state_3_exit();
                    //#[ transition 4 
                    TestConductor.ASSERT_NAME("Sensor state change", itsRobotController.getSensor(0).getLine() == true);
                    //#]
                    final_state_entDef();
                    animInstance().notifyTransitionEnded("4");
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                }
            return res;
        }
        
        //## statechart_method 
        public void state_4_entDef() {
            state_4_enter();
        }
        
        //## statechart_method 
        public int rootState_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void final_state_entDef() {
            final_state_enter();
        }
        
        //## statechart_method 
        public void initial_enter() {
            animInstance().notifyStateEntered("ROOT.initial");
            pushNullConfig();
            rootState_subState = initial;
            rootState_active = initial;
            initialEnter();
        }
        
        //## statechart_method 
        public int terminationstate_0_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void final_state_exit() {
            popNullConfig();
            final_stateExit();
            animInstance().notifyStateExited("ROOT.final_state");
        }
        
        //## statechart_method 
        public void state_1Exit() {
        }
        
        //## statechart_method 
        public void rootState_enter() {
            animInstance().notifyStateEntered("ROOT");
            rootStateEnter();
        }
        
        //## statechart_method 
        public void rootStateEnter() {
        }
        
        //## statechart_method 
        public void final_state_enter() {
            animInstance().notifyStateEntered("ROOT.final_state");
            pushNullConfig();
            rootState_subState = final_state;
            rootState_active = final_state;
            final_stateEnter();
        }
        
        //## statechart_method 
        public void initialEnter() {
        }
        
        //## statechart_method 
        public void state_3Exit() {
            itsRiJThread.unschedTimeout(TCSC_tc_0_Timeout_state_3_id, this);
        }
        
        //## statechart_method 
        public void state_4Exit() {
            itsRiJThread.unschedTimeout(TCSC_tc_0_Timeout_state_4_id, this);
        }
        
        //## statechart_method 
        public void rootState_exit() {
            switch (rootState_subState) {
                case initial:
                {
                    initial_exit();
                }
                break;
                case state_1:
                {
                    state_1_exit();
                }
                break;
                case final_state:
                {
                    final_state_exit();
                }
                break;
                case terminationstate_0:
                {
                    terminationstate_0_exit();
                }
                break;
                case state_3:
                {
                    state_3_exit();
                }
                break;
                case state_4:
                {
                    state_4_exit();
                }
                break;
                default:
                    break;
            }
            rootState_subState = RiJNonState;
            rootStateExit();
            animInstance().notifyStateExited("ROOT");
        }
        
        //## statechart_method 
        public void rootStateEntDef() {
            animInstance().notifyTransitionStarted("0");
            initial_entDef();
            animInstance().notifyTransitionEnded("0");
        }
        
        //## statechart_method 
        public void initial_exit() {
            popNullConfig();
            initialExit();
            animInstance().notifyStateExited("ROOT.initial");
        }
        
        //## statechart_method 
        public void state_1_enter() {
            animInstance().notifyStateEntered("ROOT.state_1");
            pushNullConfig();
            rootState_subState = state_1;
            rootState_active = state_1;
            state_1Enter();
        }
        
        //## statechart_method 
        public void final_stateExit() {
        }
        
        //## statechart_method 
        public int state_1_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.NULL_EVENT_ID))
                {
                    res = state_1TakeNull();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void state_3_enter() {
            animInstance().notifyStateEntered("ROOT.state_3");
            rootState_subState = state_3;
            rootState_active = state_3;
            state_3Enter();
        }
        
        //## statechart_method 
        public int state_4_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.TIMEOUT_EVENT_ID))
                {
                    res = state_4TakeRiJTimeout();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void state_4_enter() {
            animInstance().notifyStateEntered("ROOT.state_4");
            rootState_subState = state_4;
            rootState_active = state_4;
            state_4Enter();
        }
        
        //## statechart_method 
        public void state_4Enter() {
            itsRiJThread.schedTimeout(1000, TCSC_tc_0_Timeout_state_4_id, this, "ROOT.state_4");
        }
        
        //## statechart_method 
        public void rootStateExit() {
        }
        
        //## statechart_method 
        public int initialTakeNull() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("1");
            initial_exit();
            //#[ transition 1 
            itsTCon.rtc_init();
            itsRobotController.gen(new evOnOff());
            //#]
            state_4_entDef();
            animInstance().notifyTransitionEnded("1");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void initialExit() {
        }
        
        //## statechart_method 
        public int state_4TakeRiJTimeout() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.getTimeoutId() == TCSC_tc_0_Timeout_state_4_id)
                {
                    animInstance().notifyTransitionStarted("5");
                    state_4_exit();
                    //#[ transition 5 
                    TestConductor.ASSERT_NAME("Robot on",itsRobotController.isIn(RobotController.on));
                    //#]
                    state_1_entDef();
                    animInstance().notifyTransitionEnded("5");
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                }
            return res;
        }
        
        //## statechart_method 
        public int final_stateTakeNull() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("3");
            final_state_exit();
            //#[ transition 3 
            itsRobotController.gen(new evOnOff());
            itsTCon.rtc_exit();
            //#]
            terminationstate_0_entDef();
            animInstance().notifyTransitionEnded("3");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void initial_entDef() {
            initial_enter();
        }
        
        //## statechart_method 
        public void state_3Enter() {
            itsRiJThread.schedTimeout(1000, TCSC_tc_0_Timeout_state_3_id, this, "ROOT.state_3");
        }
        
        /**  methods added just for design level debugging instrumentation */
        public boolean startBehavior() {
            try {
              animInstance().notifyBehavioralMethodEntered("startBehavior",
                  new ArgData[] {
                   });
              return super.startBehavior();
            }
            finally {
              animInstance().notifyMethodExit();
            }
        }
        public int takeEvent(RiJEvent event) { 
            try { 
              //animInstance().notifyTakeEvent(new AnimEvent(event));
              animInstance().notifyBehavioralMethodEntered("takeEvent",
                  new ArgData[] { new ArgData(RiJEvent.class, "event", event.toString())
                   });
              return super.takeEvent(event); 
            }
            finally { 
              animInstance().notifyMethodExit();
            }
        }
        /**  see com.ibm.rational.rhapsody.animation.AnimatedReactive interface */
        public AnimInstance animInstance() { 
            return TCSC_tc_0.this.animInstance(); 
        }
        
    }
    //#[ ignore
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public AnimClass getAnimClass() { 
        return animClassTCSC_tc_0; 
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public Object getFieldValue(java.lang.reflect.Field f, Object userInstance) { 
         Object obj = null;
         try {
             obj = f.get(userInstance);
         } catch(Exception e) {
              System.err.println("Exception: getting Field value: " + e);
              e.printStackTrace();
         }
         return obj;
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public AnimInstance animInstance() {
        if (animate == null) 
            animate = new Animate(); 
        return animate; 
    } 
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public void addAttributes(AnimAttributes msg) {
        
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public void addRelations(AnimRelations msg) {
        
        msg.add("itsRobotController", false, true, itsRobotController);
        msg.add("itsTCon", false, true, itsTCon);
    }
    /** An inner class added as instrumentation for animation */
    public class Animate extends AnimInstance { 
        public  Animate() { 
            super(TCSC_tc_0.this); 
        } 
        public void addAttributes(AnimAttributes msg) {
            TCSC_tc_0.this.addAttributes(msg);
        }
        public void addRelations(AnimRelations msg) {
            TCSC_tc_0.this.addRelations(msg);
        }
        
        public void addStates(AnimStates msg) {
            if ((reactive != null) && (reactive.isTerminated() == false))
              reactive.rootState_add(msg);
        }
        
    } 
    //#]
    
}
/*********************************************************************
	File Path	: TPkg_RobotController_Comp/DefaultConfig/TPkg_RobotController/TCSC_tc_0.java
*********************************************************************/

